const express = require("express");
const router = express.Router();
const expressJoi = require("@escook/express-joi")
const settingHandler = require('../router_handler/setting')
// const { reg_corporateName_schema } = require("../schema/setting")
// 导入解析 formdata 格式表单数据的包
const multer = require('multer')
var storage = multer.diskStorage({
    //设置上传后文件路径，uploads文件夹会自动创建。
    destination: function (req, file, cb) {
        cb(null, path.join(__dirname, '../public/uploads'))
    },
    /**
     * 给上传文件重命名，获取添加后缀名
     * 参数名 + 文件名 + 时间戳
     * */
    filename: function (req, file, cb) {
        var fileFormat = (file.originalname).split(".");

        //  返回文件名
        cb(null, file.fieldname + '_' + fileFormat[0] + '_' + Date.now() + "." + fileFormat[fileFormat.length - 1]);
    }
});
// 导入处理路径的核心模块
const path = require('path')
// 创建 multer 的实例对象，通过 dest 属性指定文件的存放路径
// const upload = multer({ dest: path.join(__dirname, '../public/uploads') })
const upload = multer({
    storage: storage
});

router.get('/getCorporateName', settingHandler.getCorporateName)

router.post('/changeCorporateName', settingHandler.changeCorporateName)

router.get('/getCorporateInfo', settingHandler.getCorporateInfo)
router.get('/getAllCorporate', settingHandler.getAllCorporate)


router.post('/setCorporateInfo', settingHandler.setCorporateInfo)

router.get('/getSwiper', settingHandler.getSwiper)

router.post('/setSwiper', upload.single('imageUrl'), settingHandler.setSwiper)

router.get('/getDepartment', settingHandler.getDepartment)
router.post('/addDepartment', settingHandler.addDepartment)
router.post('/deleteDepartment', settingHandler.deleteDepartment)


router.get('/getProductType', settingHandler.getProductType)
router.post('/addProductType', settingHandler.addProductType)
router.post('/deleteProductType', settingHandler.deleteProductType)

module.exports = router